From: Keir Fraser Date: Wed, 12 May 2010 07:42:30 +0000 (+0100) Subject: domctl: Fix cpumap/cpumask conversion functions to return an error code. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12192 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=ed562546ce8d129a7e708e2111b905a064a0b359;p=xen.git domctl: Fix cpumap/cpumask conversion functions to return an error code. Signed-off-by: Keir Fraser --- diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hypercall.c index 26883b4d1c..81639e91f1 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -344,7 +344,8 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op) guest_from_compat_handle(cpumap_bitmap, op->u.getidletime.cpumap_bitmap); ctlmap.bitmap.p = cpumap_bitmap.p; /* handle -> handle_64 conversion */ - xenctl_cpumap_to_cpumask(&cpumap, &ctlmap); + if ( (ret = xenctl_cpumap_to_cpumask(&cpumap, &ctlmap)) != 0 ) + goto out; guest_from_compat_handle(idletimes, op->u.getidletime.idletime); for_each_cpu_mask ( cpu, cpumap ) @@ -359,7 +360,9 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op) } op->u.getidletime.now = now; - cpumask_to_xenctl_cpumap(&ctlmap, &cpumap); + if ( (ret = cpumask_to_xenctl_cpumap(&ctlmap, &cpumap)) != 0 ) + goto out; + ret = copy_to_guest(u_xenpf_op, op, 1) ? -EFAULT : 0; } break; diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c index c1af188bc3..8c049c1830 100644 --- a/xen/common/cpupool.c +++ b/xen/common/cpupool.c @@ -446,8 +446,7 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op) op->cpupool_id = c->cpupool_id; op->sched_id = c->sched.sched_id; op->n_dom = c->n_dom; - cpumask_to_xenctl_cpumap(&(op->cpumap), &(c->cpu_valid)); - ret = 0; + ret = cpumask_to_xenctl_cpumap(&(op->cpumap), &(c->cpu_valid)); } break; @@ -546,15 +545,14 @@ addcpu_out: case XEN_SYSCTL_CPUPOOL_OP_FREEINFO: { - cpumask_to_xenctl_cpumap(&(op->cpumap), - &cpupool_free_cpus); - ret = 0; + ret = cpumask_to_xenctl_cpumap( + &op->cpumap, &cpupool_free_cpus); } break; default: ret = -ENOSYS; - + break; } spin_unlock(&cpupool_ctl_lock); diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 2631960aa5..259a6b28a5 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -31,37 +31,35 @@ static DEFINE_SPINLOCK(domctl_lock); extern long arch_do_domctl( struct xen_domctl *op, XEN_GUEST_HANDLE(xen_domctl_t) u_domctl); -void cpumask_to_xenctl_cpumap( +int cpumask_to_xenctl_cpumap( struct xenctl_cpumap *xenctl_cpumap, cpumask_t *cpumask) { unsigned int guest_bytes, copy_bytes, i; uint8_t zero = 0; uint8_t bytemap[(NR_CPUS + 7) / 8]; - if ( guest_handle_is_null(xenctl_cpumap->bitmap) ) - return; - guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8; copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap)); bitmap_long_to_byte(bytemap, cpus_addr(*cpumask), NR_CPUS); if ( copy_bytes != 0 ) - copy_to_guest(xenctl_cpumap->bitmap, bytemap, copy_bytes); + if ( copy_to_guest(xenctl_cpumap->bitmap, bytemap, copy_bytes) ) + return -EFAULT; for ( i = copy_bytes; i < guest_bytes; i++ ) - copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1); + if ( copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1) ) + return -EFAULT; + + return 0; } -void xenctl_cpumap_to_cpumask( +int xenctl_cpumap_to_cpumask( cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap) { unsigned int guest_bytes, copy_bytes; uint8_t bytemap[(NR_CPUS + 7) / 8]; - if ( guest_handle_is_null(xenctl_cpumap->bitmap) ) - return; - guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8; copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap)); @@ -69,12 +67,15 @@ void xenctl_cpumap_to_cpumask( if ( copy_bytes != 0 ) { - copy_from_guest(bytemap, xenctl_cpumap->bitmap, copy_bytes); + if ( copy_from_guest(bytemap, xenctl_cpumap->bitmap, copy_bytes) ) + return -EFAULT; if ( (xenctl_cpumap->nr_cpus & 7) && (guest_bytes <= sizeof(bytemap)) ) bytemap[guest_bytes-1] &= ~(0xff << (xenctl_cpumap->nr_cpus & 7)); } bitmap_byte_to_long(cpus_addr(*cpumask), bytemap, NR_CPUS); + + return 0; } static inline int is_free_domid(domid_t dom) @@ -579,15 +580,15 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl) if ( op->cmd == XEN_DOMCTL_setvcpuaffinity ) { - xenctl_cpumap_to_cpumask( + ret = xenctl_cpumap_to_cpumask( &new_affinity, &op->u.vcpuaffinity.cpumap); - ret = vcpu_set_affinity(v, &new_affinity); + if ( !ret ) + ret = vcpu_set_affinity(v, &new_affinity); } else { - cpumask_to_xenctl_cpumap( + ret = cpumask_to_xenctl_cpumap( &op->u.vcpuaffinity.cpumap, &v->cpu_affinity); - ret = 0; } vcpuaffinity_out: diff --git a/xen/common/trace.c b/xen/common/trace.c index cc29c8b970..8b2b42183f 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -343,7 +343,7 @@ int tb_control(xen_sysctl_tbuf_op_t *tbc) tbc->size = T_INFO_PAGES * PAGE_SIZE; break; case XEN_SYSCTL_TBUFOP_set_cpu_mask: - xenctl_cpumap_to_cpumask(&tb_cpu_mask, &tbc->cpu_mask); + rc = xenctl_cpumap_to_cpumask(&tb_cpu_mask, &tbc->cpu_mask); break; case XEN_SYSCTL_TBUFOP_set_evt_mask: tb_event_mask = tbc->evt_mask; diff --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h index a0b3e15374..5ab202be7b 100644 --- a/xen/include/xen/cpumask.h +++ b/xen/include/xen/cpumask.h @@ -424,9 +424,9 @@ extern cpumask_t cpu_present_map; /* Copy to/from cpumap provided by control tools. */ struct xenctl_cpumap; -void cpumask_to_xenctl_cpumap( +int cpumask_to_xenctl_cpumap( struct xenctl_cpumap *enctl_cpumap, cpumask_t *cpumask); -void xenctl_cpumap_to_cpumask( +int xenctl_cpumap_to_cpumask( cpumask_t *cpumask, struct xenctl_cpumap *enctl_cpumap); #endif /* __XEN_CPUMASK_H */